﻿namespace Nello
{
    using System;
    using System.Security.Cryptography;
    using System.Text;

    public class HashUtil
    {
        public const int MD5 = 1;
        public const int SHA1 = 2;

        private static string Get(int type, string InputString)
        {
            string s = "";
            byte[] buffer = Encoding.Default.GetBytes(InputString);
            HashAlgorithm ha = null;
            switch (type)
            {
                case 1:
                    ha = new MD5CryptoServiceProvider();
                    break;

                case 2:
                    ha = new SHA1CryptoServiceProvider();
                    break;
            }
            buffer = ha.ComputeHash(buffer);
            for (int i = 0; i < buffer.Length; i++)
            {
                s = s + buffer[i].ToString("x").PadLeft(2, '0');
            }
            return s.ToLower();
        }

        public static string GetMD5(string inputString)
        {
            return Get(1, inputString);
        }

        public static string GetSHA1(string inputString)
        {
            return Get(2, inputString);
        }
    }
}

